package app.view.component.loading 
{
	import com.hutra.utils.NumberUtilities;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import app.facade.App;
	/**
	 * ...
	 * @author hungconcon
	 */
	
	public class ProgressBar extends MovieClip 
	{
		public var progressBar:MovieClip;
		public var psCurrent:MovieClip;
        
        public var back:MovieClip;
		
		private var done:ProgessBezier;
		private var rail:ProgessBezier;
		private var size:Number;
		private var currentValue:Number;
		private var ismousedown:Boolean = false;
		
		public function ProgressBar(value:MovieClip,thiswidth:Number) {
				progressBar = value;
				psCurrent	=progressBar.psCurrent;
				back		=progressBar.back;
				THISWIDTH = thiswidth;
			done = new ProgessBezier(psCurrent, 0, 0, CAPLEFTWIDTH,true);
			rail = new ProgessBezier(back, 		0, 0, BACKLEFTWIDTH);
			setSize(THISWIDTH);
		}
		private var CAPLEFTWIDTH:int  = 7;
		private var BACKLEFTWIDTH:int = 13;
		public var THISWIDTH:Number = 0;
		
		private function setSize(value:Number):void {
			setLimited(value-BACKLEFTWIDTH);
			setDone(0);
			setRail(value-BACKLEFTWIDTH);
		}
		private function numberReal():Number {
			var a:Number = back.left.width;
			var b:Number = (rail.width + a)-back.left.width;
			var c:Number = NumberUtilities.coPercent(mousePosition, a, b);
			return NumberUtilities.dePercent(c, 0, 100);
		}
		private function get mousePosition():Number {
			var pos:Point = back.globalToLocal(new Point(stage.mouseX, stage.mouseY));
			return pos.x;
		}
		public function setDoneValue(value:Number):void {
			done.setVisible = (value != 0);
			if (value == 0) return;
			done.repercent = (value/100);
        }
		private function setLimited(value:Number):void {
			size 		 = value;
			done.limited = value;
			rail.limited = value;
		}
		private function setDone(value:Number):void {
			done.percentage = value;
		}
		private function setRail(value:Number):void {
			rail.percentage = (value);
		}
		public function onResize(value:Number):void {
			done.resize = value;
			rail.resize = value;
			if (value < 1) {
				psCurrent.visible = false;
				back.visible = false;
			}else {
				psCurrent.visible = true;
				back.visible = true;
			}
			
		}
		
	}
}